// pages/mine/mine.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    topNum:0,
    userinfo:null,
    listData:[],
    inventory:[
      {
        id:1,
        count:0,
        title:"商品收藏"
      },
      {
        id:2,
        count:0,
        title:"店铺收藏"
      },
      {
        id:3,
        count:0,
        title:"我的收藏"
      },
    ],
    list_status:[
      {
        id:1,
        statue:1,
        font:"icon-wodedaifukuan",
        staue_display:"待支付",
      },
      {
        id:2,
        statue:2,
        font:"icon-daishouhuo",
        staue_display:"待收货",
      },
      {
        id:3,
        statue:5,
        font:"icon-31daipingjia",
        staue_display:"待评价",
      },
      {
        id:4,
        statue:6,
        font:"icon-tuihuoshouhou",
        staue_display:"退货/售后",
      },
      {
        id:1,
        statue:0,
        font:"icon-dingdan",
        staue_display:"全部订单",
        all:"查看全部"
      },
    ],
    property:[
      {
        id:1,
        account:0,
        type:"优惠券",
      },
      {
        id:2,
        account:0,
        type:"账户余额",
      },
      {
        id:3,
        account:0,
        type:"京豆",
      },
      {
        id:4,
        account:0,
        type:"红包",
      },
      {
        id:5,
        account:0,
        type:"我的资产",
      },
    ],
    games:[
      {
        id:1,
        img:"../../image/mine/fruit.jpg",
        name:"免费水果",
      },
      {
        id:2,
        img:"../../image/mine/bag.jpg",
        name:"领现金",
      },
      {
        id:3,
        img:"../../image/mine/discount.jpg",
        name:"满199-100",
      },
      {
        id:4,
        img:"../../image/mine/jing.jpg",
        name:"京豆乐园",
      },
  ],
  serice:[
    {
      id:1,
      img:"../../image/mine/serve.jpg",
      serve:"客户服务",  
    },
    {
      id:2,
      img:"../../image/mine/mail.jpg",
      serve:"寄件服务",  
    },
    {
      id:3,
      img:"../../image/mine/appointment.jpg",
      serve:"我的预约",  
    },
    {
      id:4,
      img:"../../image/mine/question.jpg",
      serve:"我的问答",  
    },
    {
      id:5,
      img:"../../image/mine/leave.jpg",
      serve:"闲置换钱",  
    },
    {
      id:6,
      img:"../../image/mine/refund.jpg",
      serve:"充值中心",  
    },
    {
      id:7,
      img:"../../image/mine/cart.jpg",
      serve:"我的爱车",  
    },
    {
      id:8,
      img:"../../image/mine/recycle.jpg",
      serve:"高价回收",  
    },
    {
      id:9,
      img:"../../image/mine/git.jpg",
      serve:"我的礼物",  
    },
    {
      id:10,
      img:"../../image/mine/recharge.jpg",
      serve:"闪电退款S+",  
    },
    {
      id:11,
      img:"../../image/mine/airticket.jpg",
      serve:"特价机票",  
    },
    {
      id:12,
      img:"../../image/mine/raffle.jpg",
      serve:"手机限时抽",  
    },
  ],
  },
  // 获取滚动条的位置
  scrolltoupper: function (e) {
    let t = e.detail.scrollTop;
    if (t > 100 && !this.data.floorstatus) {
      // 避免重复setData
      this.setData({
        floorstatus: true
      })
    }
    if (t < 100 && this.data.floorstatus) {
      this.setData({
        floorstatus: false
      })
    }
  },
  //  回到顶部
  goTop: function (e) {
    this.setData({
      topNum: 0,
    })
  },
  //跳转至订单页
  toOrderList(e){
    let status = e.currentTarget.dataset.status;
    console.log(status)
    wx.navigateTo({
      url: '/pages/mine/orderList/orderList?status= ' + status,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */  
  onLoad: function (options) {
    this.bindGetUserInfo()
   },



  bindGetUserInfo: function (e) {
    let that = this;
    wx.getUserProfile({
      desc: '用于完善会员资料',
      success: function (res) {
        console.log(res,1);
        var userinfo = res.userInfo;
        console.log(userinfo);
        that.setData({
          userinfo:userinfo
        })
        console.log('---',that.data.userinfo);
        wx.login({
          timeout: 3000,
          success: function (res) {
            console.log(res.code);
            wx.request({
              url: 'http://api_devs.wanxikeji.cn/api/codeExchangeOpenid',
              data: {
                code: res.code
              },
              method: "POST",
              header: {
                "content-type": "application/json"
              },
              success: function (res) {
                console.log(res.data);
                var openid = res.data;
                wx.request({
                  url: 'http://api_devs.wanxikeji.cn/api/register',
                  data: {
                    openid: openid.data.openid,
                    nickName: userinfo.nickName,
                    icon: userinfo.avatarUrl
                  },
                  method: "POST",
                  header: {
                    "content-type": "application/json"
                  },
                  success: function (res) {
                    console.log(res.data);
                  }

                });
                 // 存储数据
                 wx.setStorage({
                  key: "token",
                  data: res.data.data.info.token
                })
              },

            });
          },
        })
      },
    });
  },






  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 配合自定义tabBar切换
    if (typeof this.getTabBar === "function" && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 4,
      });
    }
    //懒加载区域数据
    let that = this;
    wx.request({
      url: 'http://api_devs.wanxikeji.cn/api/goodList',
      method: "post",
      success: function (res) {
        that.setData({ listData: res.data.data.data });
      },

    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () { },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () { },
})
